﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Prueba.ViewModel;
using Prueba.Model;

namespace Nav3
{
    /// <summary>
    /// Lógica de interacción para DlgFiltroFdvView.xaml
    /// </summary>
    public partial class DlgFiltroFdvView : Window
    {
        public DlgFiltroFdvView()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            FiltroFdvViewModel vm = this.DataContext as FiltroFdvViewModel;
            if (vm != null && vm.SelectedCantidad != null)
            {
                Recurso res = (from o in vm._FdvGrid.Recursos
                               where o.RecursoId == vm._SelectedRecurso
                               select o).First();
                if (res != null)
                {
                    res.FilterCantidad = vm.SelectedCantidad;
                }
                vm.IsFilter = true;
            }

            vm._FdvGrid.CvsRows.View.Refresh();
            this.Close();
        }

        private void BtnLimpiar_Click(object sender, RoutedEventArgs e)
        {
            FiltroFdvViewModel vm = this.DataContext as FiltroFdvViewModel;
            if (vm != null)
            {
                Recurso res = (from o in vm._FdvGrid.Recursos
                               where o.RecursoId == vm._SelectedRecurso
                               select o).First();
                if (res != null)
                {
                    res.FilterCantidad = null;
                }
                vm.IsClean = true;
            }

            vm._FdvGrid.CvsRows.View.Refresh();
            this.Close();
        }
    }
}
